home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.xml;
-
- import java.io.StringWriter;
- import java.io.Writer;
- import java.util.Date;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.ResourceBundle;
- import java.util.Vector;
-
- public abstract class SchemaWriter implements ExportInterface {
- boolean previewing;
- boolean showErrors;
- static ResourceBundle resourceBundle;
- NOPProxy nopProxy = new NOPProxy((SchemaWriter)null);
- PIProxy piProxy = new PIProxy(this);
- Hashtable prefixes = new Hashtable();
- SchemaIntf schema;
- URI uri;
-
- public static void setResources(ResourceBundle var0) {
- resourceBundle = var0;
- }
-
- public SchemaWriter(SchemaIntf var1, URI var2) {
- this.schema = var1;
- this.showErrors = var1.getShowErrors();
- this.setURI(var2);
- }
-
- public void writeDocument(Writer var1) {
- this.setPreviewing(false);
- SXE var2 = new SXE(var1);
- var2.writeHeader("1.0", this.schema.getEncoding());
- this.writeProlog(var2);
- this.writeValidatedBy(var2);
- this.writeHeader(var2);
- if (this.schema.getFlavor().isSupported(Class.forName("com.extensibility.xml.NamespaceDeclaration"))) {
- this.writeNamespaces(var2, this.schema.getDeclarations(this.uri, Class.forName("com.extensibility.xml.NamespaceDeclaration")));
- }
-
- if (this.showErrors) {
- this.writeParserErrors(var2);
- }
-
- if (this.schema.getFlavor() instanceof ExtraMetaDataUIIntf) {
- String[] var3 = ((ExtraMetaDataUIIntf)this.schema.getFlavor()).getNamespaces();
- int var4 = 0;
-
- while(var4 < var3.length) {
- String var5 = var3[var4++];
- String var6 = var3[var4++];
- if (this.schema.getNamedDeclaration(var5, Class.forName("com.extensibility.xml.NamespaceDeclaration")) == null) {
- var2.writeLineBreak();
- var2.writeAttr(String.valueOf("xmlns:").concat(String.valueOf(var5)), var6);
- }
- }
- }
-
- this.writeSchemaComments(var2);
- if (this.schema.getFlavor().isSupported(Class.forName("com.extensibility.xml.ExternalSubset"))) {
- this.writeIncludes(var2, this.schema.getIncludedModules(this.uri));
- }
-
- this.writeDeclarations(var2, this.schema.getDeclarations(this.uri, true));
- var2.flush();
- }
-
- public String getSourcePreview(BaseDeclaration var1) {
- this.setPreviewing(true);
- StringWriter var2 = new StringWriter();
- SXE var3 = new SXE(var2);
- this.createProxy(var1).write(var3, false);
- var3.flush();
- return var2.toString();
- }
-
- protected String getPrefix(URI var1) {
- return (String)this.prefixes.get(var1);
- }
-
- protected void setURI(URI var1) {
- this.uri = var1;
- Enumeration var2 = this.schema.getIncludedModules(var1);
-
- while(var2.hasMoreElements()) {
- ExternalSubset var3 = (ExternalSubset)var2.nextElement();
- URI var4 = var3.getSystemURI();
- int var5 = 2;
- String var6 = ((BaseDeclaration)var3).getName();
-
- String var7;
- for(var7 = var6; this.prefixes.contains(var7); var7 = String.valueOf(var6).concat(String.valueOf(var5++))) {
- }
-
- this.prefixes.put(var4, var7);
- }
-
- }
-
- protected DeclWriterProxyIntf createProxy(ElementDeclaration var1) {
- return this.nopProxy;
- }
-
- protected DeclWriterProxyIntf createProxy(AttributeDeclaration var1) {
- return this.nopProxy;
- }
-
- protected DeclWriterProxyIntf createProxy(DataTypeDeclaration var1) {
- return this.nopProxy;
- }
-
- protected DeclWriterProxyIntf createProxy(GeneralEntityDeclaration var1) {
- return this.nopProxy;
- }
-
- protected DeclWriterProxyIntf createProxy(ParameterEntityDeclaration var1) {
- return this.nopProxy;
- }
-
- protected DeclWriterProxyIntf createProxy(NotationDeclaration var1) {
- return this.nopProxy;
- }
-
- protected DeclWriterProxyIntf createProxy(NamespaceDeclaration var1) {
- return this.nopProxy;
- }
-
- protected DeclWriterProxyIntf createProxy(ExternalSubset var1) {
- return this.nopProxy;
- }
-
- protected DeclWriterProxyIntf createProxy(ProcessingInstruction var1) {
- this.piProxy.setDecl(var1);
- return this.piProxy;
- }
-
- protected DeclWriterProxyIntf createProxy(BaseDeclaration var1) {
- if (var1 instanceof ElementDeclaration) {
- return this.createProxy((ElementDeclaration)var1);
- } else if (var1 instanceof AttributeDeclaration) {
- return this.createProxy((AttributeDeclaration)var1);
- } else if (var1 instanceof GeneralEntityDeclaration) {
- return this.createProxy((GeneralEntityDeclaration)var1);
- } else if (var1 instanceof ParameterEntityDeclaration) {
- return this.createProxy((ParameterEntityDeclaration)var1);
- } else if (var1 instanceof NotationDeclaration) {
- return this.createProxy((NotationDeclaration)var1);
- } else if (var1 instanceof NamespaceDeclaration) {
- return this.createProxy((NamespaceDeclaration)var1);
- } else if (var1 instanceof ExternalSubset) {
- return this.createProxy((ExternalSubset)var1);
- } else if (var1 instanceof ProcessingInstruction) {
- return this.createProxy((ProcessingInstruction)var1);
- } else {
- return (DeclWriterProxyIntf)(var1 instanceof DataTypeDeclaration ? this.createProxy((DataTypeDeclaration)var1) : this.nopProxy);
- }
- }
-
- protected abstract void writeHeader(SXE var1);
-
- public void writeProlog(SXE var1) {
- Enumeration var2 = this.schema.getDeclarations(Class.forName("com.extensibility.xml.ProcessingInstruction"));
-
- while(var2.hasMoreElements()) {
- int var3 = var1.getLength();
- BaseDeclaration var4 = (BaseDeclaration)var2.nextElement();
- if (var4.isInProlog()) {
- this.createProxy(var4).write(var1, true);
- if (var1.getLength() > var3) {
- var1.writeLineBreak(true);
- }
- }
- }
-
- }
-
- protected void writeSchemaComments(SXE var1) {
- }
-
- protected void writeNamespaces(SXE var1, Enumeration var2) {
- }
-
- protected void writeIncludes(SXE var1, Enumeration var2) {
- }
-
- protected void writeDeclarations(SXE var1, Enumeration var2) {
- while(var2.hasMoreElements()) {
- int var3 = var1.getLength();
- BaseDeclaration var4 = (BaseDeclaration)var2.nextElement();
- if (this.showErrors && var4.hasErrors()) {
- Vector var5 = var4.getErrors();
-
- for(int var6 = 0; var6 < var5.size(); ++var6) {
- ParserException var7 = (ParserException)var5.elementAt(var6);
- var1.writeElem("exv:decl_err", -1);
- if (var7.getMessage() != null) {
- var1.writeText(var7.getMessage());
- var1.writeLineBreak();
- }
-
- if (var7.getSource() != null) {
- var1.writeText(var7.getSource());
- var1.writeLineBreak();
- }
-
- var1.flush("exv:decl_err");
- }
- }
-
- if (!var4.isInProlog()) {
- this.createProxy(var4).write(var1, true);
- }
-
- if (var1.getLength() > var3) {
- var1.writeLineBreak(true);
- }
- }
-
- }
-
- protected void writeParserErrors(SXE var1) {
- Vector var2 = this.schema.getParseErrors();
-
- for(int var4 = 0; var4 < var2.size(); ++var4) {
- ParserException var5 = (ParserException)var2.elementAt(var4);
- var1.writeElem("exv:parse_err", -1);
- if (var5.getMessage() != null) {
- var1.writeText(var5.getMessage());
- var1.writeLineBreak();
- }
-
- if (var5.getSource() != null) {
- var1.writeText(var5.getSource());
- var1.writeLineBreak();
- }
-
- var1.flush("exv:parse_err");
- }
-
- }
-
- protected void writeValidatedBy(SXE var1) {
- if (this.schema.getPrintValidatedBy()) {
- var1.writeComment(String.valueOf(" Schema validated by Extensibility on ").concat(String.valueOf((new Date()).toString())));
- }
-
- }
-
- protected String getQName(String var1, Class var2) {
- BaseDeclaration var3 = this.schema.getNamedDeclaration(var1, var2);
- if (var3 == null) {
- return var1;
- } else {
- String var4 = this.getPrefix(var3.getURI());
- return var4 == null ? var1 : String.valueOf(String.valueOf(var4).concat(String.valueOf(":"))).concat(String.valueOf(var1));
- }
- }
-
- protected void setPreviewing(boolean var1) {
- this.previewing = var1;
- }
-
- protected boolean isPreviewing() {
- return this.previewing;
- }
-
- protected void setShowErrors(boolean var1) {
- this.showErrors = var1;
- }
-
- protected boolean getShowErrors() {
- return this.showErrors;
- }
- }
-